package com.loadmore.baselibrary.util;

import android.content.Context;
import android.util.DisplayMetrics;

import com.loadmore.baselibrary.variables.Variable;

/**
 * Created by sunleilei on 2017/3/9
 */

public class ScreenUtil {

    public static DisplayMetrics getScreenMetrics(Context context) {
        DisplayMetrics metrics = context.getResources().getDisplayMetrics();
        return metrics;
    }

    public static int getScreenWidth(Context context) {
        return getScreenMetrics(context).widthPixels;
    }

    public static int getScreenHeight(Context context) {
        return getScreenMetrics(context).heightPixels;
    }

    public static int dp2px(int dp) {
        return (int) (Variable.density*dp+0.5);
    }
    public static int px2dp(int px) {
        return (int) (Variable.density/px+0.5);
    }

    public static int sp2px(int sp) {
        return (int) (Variable.scaledDensity*sp+0.5);
    }
    public static int px2sp(int px) {
        return (int) (Variable.scaledDensity/px+0.5);
    }
}
